package com.example.task;

import com.example.service.UserCouponService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class UserCouponExpiryTask {

    @Resource
    private UserCouponService userCouponService;

    @Scheduled(cron = "0 0/5 * * * ?") // 每隔5分钟执行一次，可以根据需要调整执行频率
    public void updateExpiredUserCoupons() {
        LocalDateTime now = LocalDateTime.now();
        userCouponService.updateExpiredUserCoupons(now); // 将用户优惠券状态更新为已过期
        log.info("用户优惠券过期状态更新任务完成");
    }
}